<template>
    <div>
        <el-col :span="24">
<!--            <el-row :span="2">-->
<!--                <button class="el-button&#45;&#45;warning">Welcome ! {{userDetail.username}}</button>-->
<!--                &lt;!&ndash;                <button>Welcome ! {{userDetail.username}}</button>&ndash;&gt;-->
<!--            </el-row>-->
            <el-row :span="22">
                <el-form class="dealForm"
                         :ref="dealForm"
                         :model="leave">

                    <el-form-item prop="reason" class="formItem">
                        <el-input v-model.trim="leave.reason">
                            <template slot="prepend">请假原因:</template>
                        </el-input>
                    </el-form-item>

                    <el-form-item prop="days" class="formItem">
                        <el-input type="number" v-model.trim="leave.days">
                            <template slot="prepend">请假时间:</template>
                        </el-input>
                    </el-form-item>
                    <el-form-item prop="days" class="formItem">
                        <el-input v-model.trim="leave.type">
                            <template slot="prepend">请假类型:</template>
                        </el-input>
                    </el-form-item>

                    <!--                    <el-form-item prop="type" class="formItem">请假类型：-->
                    <!--                        <el-radio-group>-->
                    <!--                            <el-radio border="" v-model="leave.type" label="1">病假-->
                    <!--                            </el-radio>-->
                    <!--                            <el-radio border="" v-model="leave.type" label="2">年假-->
                    <!--                            </el-radio>-->
                    <!--                        </el-radio-group>-->

                    <!--                    </el-form-item>-->


                    <el-form-item>
                        <el-button type="primary" icon="el-icon-edit"
                                   @click="apply">申请
                        </el-button>
                        <el-button type="warning" icon="el-icon-remove"
                                   @click="()=>$refs[dealForm].resetFields()">重置
                        </el-button>
                    </el-form-item>
                </el-form>
            </el-row>
        </el-col>


    </div>
</template>

<script>
    // import New from './components/New.vue';
    import {mapState} from 'vuex'
    // let leaveTypes=['yearLeave','sickLeave'];
    export default {


        name: "Welcome",
        components: {
            // New,Old,
        },
        props: {
            sampleP: {
                type: Number,
                default: 0
            },
        },
        data() {

            return {
                sampleD: 'value',
                dealForm: 'dealForm',
                leave: {
                    days: 2,
                    reason: '游山玩水',
                    type: "yearLeave",
                }
            }
        },
        computed: {
            ...mapState(['userDetail'])
            /*userDetail: {
            username: 'zhangsan001',
            userId: '99',
            nickname: 'Jam',
            }*/

            // sampleC() {
            //     return this.sampleD+'--';
            // }
        },
        created() {
        },
        mounted() {

            this.welcomeWord();
        },
        methods: {
            sampleM() {

            },
            apply() {
                this.$http({
                    method: 'post',
                    url: '/applyLeave',
                    data: this.leave,
                }).then(res => {
                    this.$message.warning(JSON.stringify(res.data))
                    //this.total = res.data.total;
                    //this.newsResults = res.data.results;
                }).catch(res => {
                    this.$message.warning(JSON.stringify(res.data))
                });
            },
            welcomeWord(){
                this.$notify.warning(JSON.stringify(`欢迎${this.userDetail.nickname}进入，
                您上一次登录时间是${this.userDetail.lastLoginTime}`));
            }
        },
        watch: {
            // sampleC(newValue, oldValue) {
            //
            // }
        },
    }
</script>

<style scoped>
    /*<style lang='scss' scoped>*/
    .formItem {
        margin: 5px auto;
        padding: 10px;
    }
</style>